﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core.Filter;
using System.Drawing;
using COFE.Core.Utils;
using COFE.Core;

namespace COFE.Core.EntryType
{
    public class EntryTypeInfo : IEntryTypeInfo, IEquatable<IEntryTypeInfo>
    {
        #region Constructor

        ///// <summary>
        ///// For file, from extension, set Description and MIMEType automatically.
        ///// </summary>
        ///// <param name="ext"></param>
        //protected EntryTypeInfo(string ext)
        //{            
        //    string fileType, mimeType;
        //    RegistryUtils.GetTypeInformation(ext, out fileType, out mimeType);
        //    EntryFilters = new IEntryFilter[] { new FileEntryFilter("*" + ext) };
        //    Description = fileType;
        //    MIMEType = mimeType;
        //}

        ///// <summary>
        ///// For Generic directory or file.
        ///// </summary>
        ///// <param name="isFolder"></param>
        //protected EntryTypeInfo(bool isFolder)
        //{
        //    MIMEType = null;

        //    IEntryFilter filterStr;
        //    if (isFolder)
        //    {
        //        Description = RegistryUtils.GetDirectoryDescription();
        //        filterStr = new DirectoryEntryFilter();
        //    }
        //    else
        //    {
        //        Description = RegistryUtils.GetFileDescription();
        //        filterStr = new FileEntryFilter();
        //    }

        //    EntryFilters = new IEntryFilter[] { filterStr };
        //}        

        public EntryTypeInfo(IEntryFilter[] filters, string description, string mimeType)
        {
            Filters = filters;
            Description = description;
            MIMEType = mimeType;
        }

        #endregion

        #region Methods

        public bool Equals(IEntryTypeInfo other)
        {
            string parmString = COFEShared.FilterParser.FilterToFilterString(Filters);
            string parmString2 = COFEShared.FilterParser.FilterToFilterString(other.Filters);
            return parmString.Equals(parmString2);
        }

        public override bool Equals(object obj)
        {
            if (obj is IEntryTypeInfo)
                return this.Equals(obj as IEntryTypeInfo);
            return false;
        }

        public override int GetHashCode()
        {
            return ID.GetHashCode();
        }

        #endregion

        #region Data

        private IEntryFilter[] _filters = null;
        private string _description = null;
        private string _mimeType = null;

        #endregion

        #region Public Properties

        public Guid ID
        {
            get
            {
                return StringUtils<IEntryFilter>.GetDeterministicGuid(
                    COFEShared.FilterParser.FilterToFilterString(Filters));
            }
        }
        public IEntryFilter[] Filters { get { return _filters; } protected set { _filters = value; } }
        public string Description { get { return _description; } protected set { _description = value; } }
        public string MIMEType { get { return _mimeType; } protected set { _mimeType = value; } }

        #endregion


    }
}
